package classFile;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

public class Main {
    static Unsafe unsafe;

    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        System.out.println("hello world");
        Field field = Unsafe.class.getDeclaredField("theUnsafe");
        field.setAccessible(true);
        unsafe = (Unsafe) field.get(null);
        Integer i = new Integer(20000);
        System.out.println(i);
        int l = unsafe.arrayBaseOffset(Integer.class);
        int size = unsafe.addressSize();
        long objectAddress;
        switch (size) {
            case 4:
                objectAddress = unsafe.getInt(i, l);
                break;
            case 8:
                objectAddress = unsafe.getLong(i, l);
                break;
            default:
                throw new Error("unsupported address size: " + l);
        }
        System.out.println(objectAddress);
    }
}
